package com.spider.silence.main;

import com.spider.silence.downloader.ChengduLifeDownLoader;
import com.spider.silence.pool.ChengduLifeDownLoaderPool;
import com.spider.silence.utils.PropertiesUtil;
import com.spider.silence.worker.ChengduLifeWorker;
import org.apache.log4j.PropertyConfigurator;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by qiuhao on 2017/1/11.
 */
public class ChengduLifeMain {

    public static void main(String[] args) throws  Exception{
        PropertyConfigurator.configure( PropertiesUtil.getLogPro());

        ChengduLifeDownLoaderPool downLoaderPool= ChengduLifeDownLoaderPool.getInstance();

        ChengduLifeDownLoader downLoader=downLoaderPool.fetchDownLoader(1000);

        List<String> urlList=downLoader.getModulesUrlList();
//        List<String> list=new ArrayList<String>();
//        list.add("http://www.028sh.com/forum.php?mod=forumdisplay&fid=51&filter=sortall&sortall=1");
        downLoader.generateTask(urlList);

        downLoaderPool.releaseDownLoader(downLoader);

        ExecutorService pool =  Executors.newFixedThreadPool(Integer.valueOf(PropertiesUtil.getVal("main.woker.size")));

        for(int i=0;i<Integer.valueOf(PropertiesUtil.getVal("ChengDuLife.WorkerCount"));i++){
            pool.execute(new ChengduLifeWorker());
        }
    }

}
